package com.mz.mattress.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mz.mattress.admin.api.req.MemberCashOutOrderQueryReq;
import com.mz.mattress.admin.mapper.MemberCashOutOrderMapper;
import com.mz.mattress.admin.service.MemberCashOutOrderService;
import com.mz.mattress.admin.util.ExcelUtil;
import com.mz.mattress.api.common.Result;
import com.mz.mattress.api.entity.MemberCashOutOrder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;

@Service
@Slf4j
public class MemberCashOutOrderServiceImpl implements MemberCashOutOrderService {

    @Autowired
    private MemberCashOutOrderMapper memberCashOutOrderMapper;

    @Override
    public Result<IPage<MemberCashOutOrder>> listPage(MemberCashOutOrderQueryReq req) {

        IPage<MemberCashOutOrder> list = memberCashOutOrderMapper.listPage(req.newPage(),
                req.getName(), req.getType(), req.getStatus(), req.getStartTime(), req.getEndTime());
        return Result.ok(list);
    }

    @Override
    public void exportList(HttpServletResponse response, MemberCashOutOrderQueryReq req) {

        IPage<MemberCashOutOrder> list = memberCashOutOrderMapper.listPage(req.newPage().setSize(1000),
                req.getName(), req.getType(), req.getStatus(), req.getStartTime(), req.getEndTime());

        ExcelUtil.simpleDownload(response, "提现记录", list.getRecords());
    }

    @Override
    public Result<MemberCashOutOrder> getById(Integer id) {

        MemberCashOutOrder order = memberCashOutOrderMapper.selectById(id);
        return Result.ok(order);

    }

}
